//
//  KYClassCell.m
//  kuaiyi
//
//  Created by 杨亮 on 16/3/12.
//  Copyright © 2016年 kuaiyi. All rights reserved.
//

#import "KYClassCell.h"
#import <Masonry.h>
#import "KYClassModel.h"
#import "Header.h"

@interface KYClassCell ()
@property (nonatomic, strong)UIImageView *iconImage;
@property (nonatomic, strong)UILabel *nameLabel;
@end
@implementation KYClassCell
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:CGRectZero]) {
        [self setUpUI];
    }
    return self;
}
-(void)setUpUI{
    UIImageView *imageView = [[UIImageView alloc]init];
    self.iconImage = imageView;
    imageView.image = [UIImage imageNamed:@"class_0"];
    
    UILabel *nameLabel = [[UILabel alloc]init];
    self.nameLabel = nameLabel;
    nameLabel.text = @"公益活动";
    nameLabel.textAlignment = NSTextAlignmentCenter;
    nameLabel.font = [UIFont systemFontOfSize:14];
    //注意要加在contentView上
    [self.contentView addSubview:imageView];
    [self.contentView addSubview:nameLabel];
}
//一定要在这里设置frame,否则出不来
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize cellSize = self.contentView.frame.size;
    CGFloat iconW = 50;
    CGFloat iconX = (cellSize.width - iconW)/2;
    CGFloat iconY = (cellSize.height - 60)/2;
    self.iconImage.frame = CGRectMake(iconX, iconY, iconW, iconW);
    self.nameLabel.frame = CGRectMake(0, CGRectGetMaxY(self.iconImage.frame)+5, cellSize.width, 20);
    
}
-(void)setClassModel:(KYClassModel *)classModel{
    _classModel = classModel;
    self.iconImage.image = [UIImage imageNamed:classModel.icon];
    self.nameLabel.text = classModel.name;
}
@end
